]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
dbusServices/extensions: Add basic extension manager
authorFlorian Müllner <fmuellner@gnome.org>
Sun, 9 Jul 2023 10:47:05 +0000 (12:47 +0200)
committerMarge Bot <marge-bot@gnome.org>
Sat, 15 Jul 2023 11:07:12 +0000 (11:07 +0000)
ExtensionUtils' getCurrentExtension() method currently either
returns the extension that was injected with setCurrentExtension(),
or imports Main locally to access the extensionManager.

But local imports won't work anymore when we convert to ESM,
and setCurrentExtension() is only an option for prefs.

Instead of diverging the code paths even further, we'll unify
the two cases as much as possible.

As a first step, add a basic extension manager in the Extensions
D-Bus service that exposes the same lookup() API as the "real"
extension manager.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2832>

js/dbusServices/extensions/extensionsService.js

index 4ef58babf2807e208f62457c1c55615dfa9b46da..4af99f8e3b2c09f4b3ecb17599056a6c7731896d 100644 (file)
@@ -6,12 +6,28 @@ import Shew from 'gi://Shew';
 import {ExtensionPrefsDialog} from './extensionPrefsDialog.js';
 import {ServiceImplementation} from './dbusService.js';
 
-const ExtensionUtils = imports.misc.extensionUtils;
+const {deserializeExtension} = imports.misc.extensionUtils;
 const {loadInterfaceXML} = imports.misc.dbusUtils;
 
 const ExtensionsIface = loadInterfaceXML('org.gnome.Shell.Extensions');
 const ExtensionsProxy = Gio.DBusProxy.makeProxyWrapper(ExtensionsIface);
 
+class ExtensionManager {
+    #extensions = new Map();
+
+    createExtensionObject(serialized) {
+        const extension = deserializeExtension(serialized);
+        this.#extensions.set(extension.uuid, extension);
+        return extension;
+    }
+
+    lookup(uuid) {
+        return this.#extensions.get(uuid);
+    }
+}
+
+const extensionManager = new ExtensionManager();
+
 export const ExtensionsService = class extends ServiceImplementation {
     constructor() {
         super(ExtensionsIface, '/org/gnome/Shell/Extensions');
@@ -118,7 +134,7 @@ export const ExtensionsService = class extends ServiceImplementation {
                 throw new Error('Already showing a prefs dialog');
 
             const [serialized] = await this._proxy.GetExtensionInfoAsync(uuid);
-            const extension = ExtensionUtils.deserializeExtension(serialized);
+            const extension = extensionManager.createExtensionObject(serialized);
 
             this._prefsDialog = new ExtensionPrefsDialog(extension);
             this._prefsDialog.connect('realize', () => {